package com.cande.loki.exercise.testspring;



import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @auther ROCK CODER
 * @DATE 2022/3/13 8:54
 * @Description
 */
public class TestSpring {
    public static void main(String[] args) throws ClassNotFoundException {
        ApplicationContext context = new AnnotationConfigApplicationContext(BeanConfig.class);

        User user = context.getBean(User.class);
//        System.out.println(user);
        String[] beanDefinitionNames = context.getBeanDefinitionNames();
        for (String name: beanDefinitionNames) {
            System.out.println(name);
        }
        User2 CC = (User2)context.getBean("hhhh");
        System.out.println(CC);

        //推断main方法所在的类
        StackTraceElement[] stackTrace = new RuntimeException().getStackTrace();
        for (StackTraceElement stackTraceElement : stackTrace) {
            if ("main".equals(stackTraceElement.getMethodName())) {
                System.out.println( Class.forName(stackTraceElement.getClassName()));
            }
        }
    }
}
